<?php
session_start();
ini_set("magic_quotes_gpc", "Off");
ini_set("output_buffering", "On");
ini_set("default_charset", "UTF-8");

// Include config file
include_once("conf/conf.php");
require_once(LIB_UI_DIR . "/FunctionCommon.class.php");
require_once(LIB_CORE_DIR . "/Session.class.php");
include_once(LIB_CORE_DIR . "/Validator.class.php");

$folder = '/' . FunctionCommon::getLanguage();
$oauth_token = FunctionCommon::getGet(array('oauth_token'));
if ($oauth_token['oauth_token'] != null) {
	include_once(LIB_CORE_DIR . "/ControllerAdmin.class.php");
	include_once(LIB_CORE_DIR . "/ViewAdmin.class.php");
	require_once(LIB_CORE_DIR . "/MessageHelper.class.php");
	$folder = '/admin';
} else {
	constants::$pathUrl = '';
	include_once(LIB_CORE_DIR . "/Controller.class.php");
	include_once(LIB_CORE_DIR . "/View.class.php");
}

if (isset($_GET['lg']) && $_GET['lg'] != '') {
	Session::Set('LANGUAGE', substr($_GET['lg'], 0, -1));
	$folder = '/' . substr($_GET['lg'], 0, -1);
}

// Request action
$module = isset($_REQUEST["m"]) && $_REQUEST["m"] != '' ? $_REQUEST["m"] : "home" ;
$action = isset($_REQUEST["a"]) && $_REQUEST["a"] != '' ? $_REQUEST["a"] : "index" ;

// Include action file
$className = FunctionCommon::getControllerClass($module);
$actionFile = MODULE_DIR . $folder . "/actions/" . $className . ".php";
if (is_file($actionFile)) {
	require($actionFile);
	// Action
	$objController = new $className ();
	$objController->templateFile = $module."/".$action;
	$actionController = 'action'.ucfirst($action);
	$objController->$actionController();
}
?>